package com.atguigu.eduservice.controller.index;

import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

//@CrossOrigin
@RestController
@RequestMapping("/eduservice/indexfront")
public class IndexController {



    @Autowired
    private EduCourseService courseService;

    @Autowired
    private EduTeacherService teacherService;

    @GetMapping("allIndex")
    public R getAllIndex(){

        //查询前8条热门课程，查询前4条名师
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("view_count");
        wrapper.last("limit 8");

        List<EduCourse> list = courseService.list(wrapper);

        QueryWrapper<EduTeacher> teacherWrapper = new QueryWrapper<>();

        teacherWrapper.orderByDesc("id");
        teacherWrapper.last("limit 4");

        List<EduTeacher> teacherList = teacherService.list(teacherWrapper);

        Map<String, Object> map = new HashMap<>();
        map.put("eduList", list);
        map.put("teacherList", teacherList);

        return R.ok().data(map);


    }


}
